#ifndef HTSC_REQUESTS_CONTROLLER_UTILS_H
#define HTSC_REQUESTS_CONTROLLER_UTILS_H

#include <stdint.h>
#include<map>
#include<string>

#ifdef __cplusplus
extern "C" {
#endif

class RequestsControllerUtils
{

public:
	RequestsControllerUtils() {};
	~RequestsControllerUtils() {};
	void SetMaxRequestMap(std::string service_name, long maxRequest);
	//检查某服务的单位时间内的请求数是否小于最大请求数，满足条件返回true，否则返回false
	bool CheckRequest(std::string service_name);
	void DecreaseRequest(std::string service_name);

private:
	bool CheckRequestInner(std::map<std::string, long>::iterator max_request_iter,std::string service_name,uint64_t current_time);
private:
	std::map<std::string, long> max_request_vec_;
	std::map<std::string, uint64_t> last_invoke_time_vec_;
	std::map<std::string, long> request_num_counters_vec_;
};

#ifdef __cplusplus
}
#endif

#endif


